// Copyright (c) Microsoft Corporation.  All rights reserved.

#pragma once

namespace Microsoft { namespace Samples { namespace SqlServer { namespace SSIS { namespace EventLogSource {
	ref class EventFile;

	// TODO make internal
	public ref class EventEnumerator : public System::Collections::IEnumerator {
	private:
		static const UInt32 FORWARD_READ = EVENTLOG_SEQUENTIAL_READ | EVENTLOG_FORWARDS_READ;
		static const UInt32 RESTART_READ = EVENTLOG_SEEK_READ | EVENTLOG_FORWARDS_READ;

		DWORD bufferSize;
		LPVOID buffer;
		PEVENTLOGRECORD logRecord;
		EventRecord^ record;
		DWORD bytesRead;
		EventFile^ eventFile;
		UInt32 flags;

		EventEnumerator() {};
		void EnsureBuffer(DWORD size);
		void ReleaseBuffer();

	public:
		EventEnumerator(EventFile^ eventFile);
		~EventEnumerator() { this->!EventEnumerator(); }
		!EventEnumerator();
		virtual property Object^ Current { Object^ get() { return this->record; } }
		virtual bool MoveNext();
		virtual void Reset() { this->flags = RESTART_READ; }
		void DebugRead();
	};
} } } } }